package com.rd.student.ruanjian.class4.lichunquan.Text02;

import java.util.Random;
public class Test10 {
    //转换罗马数字
    public static void main(String[] args) {
        Random random = new Random();
        StringBuilder loma = new StringBuilder();
        int number = random.nextInt(3999)+1;
        System.out.println(number);
        String[][] str = {{"I","V","X"}, {"X","L","C"},{"C","D","M"},{"M"}};
        //构建反向字符串
        for (int i = 0; i < 4; i++) {
            int size = number % 10;
            number/=10;
            if( size == 9){
                loma.append(str[i][2]).append(str[i][0]);
            }else if(size > 5){
                while(size-5 > 0){
                    loma.append(str[i][0]);
                    size--;
                }
                loma.append(str[i][1]);
            }else if(size == 5){
                loma.append(str[i][1]);
            }else if(size == 4){
                loma.append(str[i][0]).append(str[i][1]);
            }else {
                while(size>0){
                    loma.append(str[i][0]);
                    size--;
                }
            }
        }
        //反转字符串，得到最终罗马数字
        System.out.println(loma.reverse());
    }
    public static void test11(){
        String[][] checkerboard = new String[3][3];
    }
}

